// Copyright (c) 2021 Presto Labs Pte. Ltd.
// Author: fengyang

#pragma once

#include <map>
#include <memory>
#include <regex>
#include <string>
#include <vector>

// internal
#include "coin2/exchange/base/feed/processor.h"
#include "coin2/exchange/base/market/enums.h"
#include "coin2/exchange/di/constant.h"

#include "quickfix/Message.h"
#include "quickfix/SessionSettings.h"

namespace coin2::exchange::lmax_digital::feed_v1 {
namespace impl {
class LmaxdigitalFeedProcessor : public base::feed::FeedParsingProcessor {
 public:
  explicit LmaxdigitalFeedProcessor(
      const std::string& system_name,
      const coin2::exchange::di::ConstantInjection& ci,
      const feed::RawParserConfig& config,
      const MarketExchangeApi& mea);

  void OnTopicRecord(const base::executor::TopicRecordPacket& packet) override;

 private:
  struct TradeEntry {
    PriceQty trade;
    int64_t time;
  };

  struct BookEntry {
    std::vector<PriceQty> asks;
    std::vector<PriceQty> bids;
  };

  void PushEntry(
    const FIX::MDUpdateAction& action,
    const FIX::MDEntryPositionNo& no,
    const PriceQty& price_qty,
    std::vector<PriceQty>* entries);
  void UpdateFeed(
    const std::string& native_symbol,
    int64_t feed_time,
    bool book_update);
  BookEntry& BookCache(const std::string& native_symbol);

  int market_depth_;
  FIX::DataDictionary dict_;
  std::map<std::string, BookEntry> book_cache_;
  std::vector<TradeEntry> trades_;
};
};  // namespace impl
using impl::LmaxdigitalFeedProcessor;
}  // namespace coin2::exchange::lmax_digital::feed_v1
